package com.xt.purchasingsystem.controller.productionManagement;

import com.xt.purchasingsystem.dto.MDesignProcedureDetailsDto;
import com.xt.purchasingsystem.dto.MDesignProcedureDto;
import com.xt.purchasingsystem.model.MDesignProcedure;
import com.xt.purchasingsystem.service.productionManagementService.ProcessMaterialDesignService;
import com.xt.purchasingsystem.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;

/**
 * 生产管理--工序物料设计接口
 * Author: 老姚
 * Date:  2020/3/17 16:49
 */
@RestController
@RequestMapping(value = "/processMaterialDesign")
public class ProcessMaterialDesignController {
    @Autowired
    private ProcessMaterialDesignService processMaterialDesignService;

    //分页查询所有 已审核 工序物料未设计 的产品生产工序单的接口
    @GetMapping("/canMakeProcessMaterialDesignList")
    public Result canMakeProcessMaterialDesignList(MDesignProcedureDto mDesignProcedureDto) {
        return processMaterialDesignService.queryAllapprovedMDesignProcedureByPaging(mDesignProcedureDto);
    }

    //点击制定 根据产品编号查询此产品所有所需物料的接口
    @GetMapping("/queryAllDModuleDetailsByProductId")
    public Result queryAllDModuleDetailsByProductId(HttpServletRequest request) {
        String productId = request.getParameter("productId");
        int currNo = Integer.parseInt(request.getParameter("currNo"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        return processMaterialDesignService.queryAllDModuleDetailsByProductId(productId, currNo, pageSize);
    }

    /**
     * 根据工序编号获取此工序已设计的物料的接口
     *
     * @param procudureId
     * @return
     */
    @GetMapping("/getAllMDesignProcedureModuleByProcudureId/{procudureId}")
    public Result getAllMDesignProcedureModuleByProcudureId(@PathVariable Integer procudureId) {
        return processMaterialDesignService.getAllMDesignProcedureModuleByProcudureId(procudureId);
    }

    /**
     * 产品生产工序设计物料的接口
     *
     * @return
     */
    @PostMapping("/designMaterial")
    public Result designMaterial(@RequestBody MDesignProcedureDetailsDto mDesignProcedureDetailsDto) {
        return processMaterialDesignService.designMaterial(mDesignProcedureDetailsDto);
    }

    //产品生产工序重新设计物料的接口
    @PostMapping("/redesign")
    public Result redesign(@RequestBody MDesignProcedureDetailsDto mDesignProcedureDetailsDto) {
        return processMaterialDesignService.redesign(mDesignProcedureDetailsDto);
    }

    //提交设计单的接口
    @GetMapping("/submitProcessMaterialDesignSheet/{id}/{productId}")
    public Result submitProcessMaterialDesignSheet(@PathVariable Integer id, @PathVariable String productId) {
        return processMaterialDesignService.submitProcessMaterialDesignSheet(id, productId);
    }

    //检查是否还有剩余物料的接口
    @GetMapping("/checkMaterialResidualAmount/{productId}")
    public Result checkMaterialResidualAmount(@PathVariable String productId) {
        return processMaterialDesignService.checkMaterialResidualAmount(productId);
    }

    //分页查询所有 已审核 工序物料已提交 的产品生产工序单的接口
    @GetMapping("/getAllMDesignProcedureModuleBycheckedAndMaterialDesigned")
    public Result getAllMDesignProcedureModuleBycheckedAndMaterialDesigned(MDesignProcedureDto mDesignProcedureDto) {
        return processMaterialDesignService.queryAllMDesignProcedureModuleBycheckedAndMaterialDesigned(mDesignProcedureDto);
    }

    //审核工序物料设计单的接口
    @PutMapping("/reviewProcessMaterialDesignList")
    public Result reviewProcessMaterialDesignList(@RequestBody MDesignProcedure mdesignProcedure) {
        System.out.println(mdesignProcedure);
        return processMaterialDesignService.reviewProcessMaterialDesignList(mdesignProcedure);
    }

}
